final float TICKET_ANIMATION_SPEED  = 1.5;
class Sidebar
{
  private float x;
  private float y;
  private int tWidth;
  private int tHeight;
  private boolean animate, isExtended;
  private float interpolateTimer;
  private int visibleHeight;
  private int hideHeight;
  PImage background;


  Sidebar(float x, float y, int tWidth, int tHeight) {
    this.x = x;
    this.y = y;
    this.tWidth = tWidth;
    this.tHeight = tHeight;
    hideHeight  = 30;
    visibleHeight = hideHeight-1;
    animate = false;

    isExtended = false;
    background = loadImage("sidebar_2.png");
    interpolateTimer = 0.0;
  }

  public void render(float dT)
  {
    if(!isExtended && animate)
    {
      interpolateTimer += dT;
      if( visibleHeight != tHeight) {
        if(  interpolateTimer <TICKET_ANIMATION_SPEED / 4 ) {
          interpolateTimer = TICKET_ANIMATION_SPEED / 4;
        }
        else if( interpolateTimer >= (3 * TICKET_ANIMATION_SPEED) / 4 ) {
          interpolateTimer = (3 * TICKET_ANIMATION_SPEED) / 4;
          animate = false;
          isExtended = true;
        }
        visibleHeight = (int)map(interpolateTimer, TICKET_ANIMATION_SPEED / 4, (3 * TICKET_ANIMATION_SPEED) / 4, hideHeight-1, tHeight);
        //println("visibleHeight is "+visibleHeight+",animate is "+animate+",isExtended is"+ isExtended);
        //if( animate == false) airplaneInPosition = false;
      }
    }
    else if( isExtended && animate)
    {
      interpolateTimer += dT;
      /*if( interpolateTimer > TICKET_ANIMATION_SPEED ) {
       interpolateTimer = TICKET_ANIMATION_SPEED;
       }
       else */
      if(  interpolateTimer > (3 * TICKET_ANIMATION_SPEED) / 4 ) {
        interpolateTimer = (3 * TICKET_ANIMATION_SPEED) / 4;
      }

      visibleHeight = (int)map(interpolateTimer, 0, (3 * TICKET_ANIMATION_SPEED) / 4, tHeight, hideHeight-1);
      if( interpolateTimer == (3 * TICKET_ANIMATION_SPEED) / 4 ) 
      {   
        animate = false;
        isExtended = false;
      }
    }

    pushMatrix();
    translate(0,-tHeight + visibleHeight);
    image(background, 0, 0, background.width, background.height);
    //println( "-tWidth + visibleHeight is "+(-tWidth + visibleHeight));
    noStroke();


    textFont(font, 20);
    textAlign(CENTER, CENTER);
    fill(0);
    text("GRAPHS",x,tHeight-hideHeight,tWidth,hideHeight);
    gr.draw();

    popMatrix();
  }

  public void mouseClicked() {

    if( !animate && mouseX < tWidth && mouseY < hideHeight ) {
      animate = true;
      interpolateTimer = 0.0;
      println("clicked");
    }
    else if( !animate && isExtended && mouseX < tWidth && mouseY >height-hideHeight*2 ) 
    {
      animate = true;
      interpolateTimer = 0.0;
      //println("clicked");
    }
  }
}

